home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-04-24 | 3.6 KB | 138 lines | [TEXT/MPS ] |
- program DragExample2;
- {$D+} {put in debug names}
- {$R+} {range checking on}
- {$OV+} {overflow checking on}
- {$N+} {pass routine names to linker, so they're not anonymous}
- USES {$LOAD pinterfaces.dump}
- MemTypes,QuickDraw,OsIntf,PasLibIntf,ToolIntf,
- PackIntf,IntEnv,CursorCtl,
- {$LOAD}
- {$U UDrag.p} DragManager;
-
- var
- myPic : PicHandle;
- myRect : Rect;
- wPort: GrafPtr;
- whichPict,
- x,y,xinc,yinc : integer;
- xyPt, lastXYPt : point;
- myEventRecord : EventRecord;
- lastCount : longint;
-
- myDragStuff : DragHandle;
-
- procedure Debugger; { turned off for now
- INLINE $A9FF;}
- begin
- {stub}
- end;
-
- procedure BounceItAround;
- begin
- GetMouse(xyPt);
- xinc := xyPt.h;
- yinc := xyPt.v;
- {starting position}
- y := (screenBits.bounds.right - screenBits.bounds.left) div 2;
- x := (screenBits.bounds.bottom - screenBits.bounds.top) div 2;
- {changes don't occur until the focal point moves, so
- this makes sure it's drawn the first time.}
- SetPt(lastXYPt, -100, -100);
- repeat
- GetMouse(xyPt);
- {use the cursor position to set the velocity of the
- bouncing picture. It doesn't change the direction,
- just the speed.}
- if xinc > 0 then xinc := xyPt.h else xinc := -xyPt.h;
- if yinc > 0 then yinc := xyPt.v else yinc := -xyPt.v;
- {move the focal point}
- x := x + xinc;
- y := y + yinc;
- {keep it on the screen and bounce off the edges if needed}
- with screenBits.bounds do
- if y < top then
- begin y := top; yinc := -yinc; end
- else if y > bottom then
- begin y := bottom; yinc := -yinc; end;
-
- with screenBits.bounds do
- if x < left then
- begin x := left; xinc := -xinc; end
- else if x > right then
- begin x := right; xinc := -xinc; end;
-
- SetPt( xyPt, x, y );
-
- {if the movement is far enough, the next line of code (commented out)
- can be used to make the image persist long enough that it doesn't appear
- ghostly. On the other hand, if the movement is very small, the image
- generally looks nice and solid and does not benefit from delays.}
- {if TickCount >= lastCount + 2 then}
- if not EqualPt( xyPt, lastXYPt) then
- begin
- {if CapsLockKey, don't show the shadow, else show it}
- if EventAvail(0, myEventRecord) then {twiddle thumbs};
- if BTST(myEventRecord.modifiers, 10)
- then with shadowStuff do
- begin dx := 0; dy := 0; visible := false; end
- else with shadowStuff do
- begin
- dx := xyPt.h div 8 - 32;
- dy := xyPt.v div 8 - 20;
- visible := true;
- end;
-
- DragItTo( myDragStuff, xyPt, true );
-
- lastXYPt := xyPt;
- lastCount := TickCount;
- end;
- {allow for FKEY access and give DAs and such time}
- if GetNextEvent( keyDownMask, myEventRecord ) then {do nothing};
- SystemTask;
- until button;
- repeat until not button;
- end; {bounceitaround}
-
- begin{main}
- InitGraf(@thePort);
-
- {standalones need to init windows, but tools shouldn't}
- if IEStandalone then InitWindows;
-
- GetWMgrPort( wPort );
- SetPort( wPort );
- ClipRect( screenBits.bounds );
- InitCursor;
-
- if not InitDrag( nil ) then exit( DragExample2 );
-
- for whichPict := 1 to CountResources('PICT') do
- begin
- myPic := PicHandle(GetIndResource('PICT', whichPict));
- if myPic = nil then
- begin SysBeep(1); exit(DragExample2); end;
- if not NewDraggable( myPic, nil, nil, myDragStuff )
- then exit(DragExample2);
- BounceItAround;
- DisposeDraggable( myDragStuff );
- { Use this code to take a look at pictures that
- display some behavior you don't understand.}
- { repeat until not button;
- repeat until button;
- FillRect( screenBits.bounds, white );
- HLock( Handle( myPic ));
- DrawPicture( myPic, myPic^^.picFrame );
- myRect := myPic^^.picFrame;
- with myRect do
- OffsetRect( myRect, -left, -top );
- DrawPicture( myPic, myRect );
- HUnlock( Handle( myPic ));
- }
- ReleaseResource( Handle( myPic ));
- end;
-
- CloseDrag( true );
-
- end.
-